package com.lucifer.treasure.registry;

import com.lucifer.treasure.config.ConfigHandler;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;

public class EnchantRegistry {

    // AutoSmelt - 自动熔炼
    public static final RegistryKey<Enchantment> AUTO_SMELT = of("auto_smelt");
    
    // Step - 自动步行  
    public static final RegistryKey<Enchantment> STEP = of("step");
    
    // Venom - 毒液
    public static final RegistryKey<Enchantment> VENOM = of("venom");
    
    // Excavation - 连锁挖掘
    public static final RegistryKey<Enchantment> EXCAVATION = of("excavation");
    
    // Steady - 稳定
    public static final RegistryKey<Enchantment> STEADY = of("steady");
    
    // XP Boost - 经验提升
    public static final RegistryKey<Enchantment> EXPERIENCE_BOOST = of("experience_boost");
    
    // Traveller - 旅行者
    public static final RegistryKey<Enchantment> TRAVELLER = of("traveller");
    
    // Beekeeper - 养蜂人
    public static final RegistryKey<Enchantment> BEEKEEPER = of("beekeeper");
    
    // Beheading - 斩首
    public static final RegistryKey<Enchantment> BEHEADING = of("beheading");
    
    // Disarm - 缴械
    public static final RegistryKey<Enchantment> DISARM = of("disarm");
    
    // Growth - 生长
    public static final RegistryKey<Enchantment> GROWTH = of("growth");
    
    // Life Leech - 生命汲取
    public static final RegistryKey<Enchantment> LIFE_LEECH = of("life_leech");
    
    // Magnet - 磁力
    public static final RegistryKey<Enchantment> MAGNET = of("magnet");
    
    // Reach - 伸展
    public static final RegistryKey<Enchantment> REACH = of("reach");
    
    // Block Reach - 方块范围扩展
    public static final RegistryKey<Enchantment> BLOCK_REACH = of("block_reach");
    
    // Multi-Bow - 多重射击
    public static final RegistryKey<Enchantment> MULTIBOW = of("multibow");
    
    // Quickdraw - 快速拉弓
    public static final RegistryKey<Enchantment> QUICKDRAW = of("quickdraw");
    
    // Multi-Jump - 多重跳跃
    public static final RegistryKey<Enchantment> MULTIJUMP = of("multijump");
    
    // Last Stand - 最后抵抗
    public static final RegistryKey<Enchantment> LASTSTAND = of("laststand");
    
    // Gloom Curse - 阴郁诅咒
    public static final RegistryKey<Enchantment> GLOOM_CURSE = of("gloom_curse");
    
    // Ender Pearl - 末影
    public static final RegistryKey<Enchantment> ENDER_PEARL = of("ender_pearl");

    // Sword Aura - 御剑术
    public static final RegistryKey<Enchantment> SWORD_AURA = of("sword_aura");

    private static RegistryKey<Enchantment> of(String name) {
        return RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("lucifer_treasure", name));
    }

    public static void registerEnchantments() {
        // 在 Minecraft 1.21.1 中，我们只注册 RegistryKey
        // 附魔效果通过事件监听器工作，不需要数据包
        
        // Initialize configurations
        initializeConfigs();
    }

    private static void initializeConfigs() {
        // Initialize config values for each enchantment
        // 所有附魔默认启用
        ConfigHandler.enchantEnabled("auto_smelt", true);
        ConfigHandler.enchantEnabled("step", true);
        ConfigHandler.enchantEnabled("steady", true);
        ConfigHandler.enchantEnabled("experience_boost", true);
        ConfigHandler.enchantEnabled("traveller", true);
        ConfigHandler.enchantEnabled("magnet", true);
        ConfigHandler.enchantEnabled("excavation", true);
        ConfigHandler.enchantEnabled("reach", true);
        ConfigHandler.enchantEnabled("venom", true);
        ConfigHandler.enchantEnabled("beheading", true);
        ConfigHandler.enchantEnabled("disarm", true);
        ConfigHandler.enchantEnabled("growth", true);
        ConfigHandler.enchantEnabled("life_leech", true);
        ConfigHandler.enchantEnabled("beekeeper", true);
        ConfigHandler.enchantEnabled("block_reach", true);
        ConfigHandler.enchantEnabled("multibow", true);
        ConfigHandler.enchantEnabled("quickdraw", true);
        ConfigHandler.enchantEnabled("multijump", true);
        ConfigHandler.enchantEnabled("laststand", true);
        ConfigHandler.enchantEnabled("gloom_curse", true);
        ConfigHandler.enchantEnabled("ender_pearl", true);
        ConfigHandler.enchantEnabled("sword_aura", true);
    }
    
    /**
     * 检查指定附魔是否启用
     * @param enchantName 附魔名称
     * @return true表示启用，false表示禁用
     */
    public static boolean isEnchantEnabled(String enchantName) {
        return ConfigHandler.isEnchantEnabled(enchantName);
    }
    
    /**
     * 检查指定附魔键是否启用
     * @param enchantKey 附魔的 RegistryKey
     * @return true表示启用，false表示禁用
     */
    public static boolean isEnchantEnabled(RegistryKey<Enchantment> enchantKey) {
        String enchantName = enchantKey.getValue().getPath();
        return ConfigHandler.isEnchantEnabled(enchantName);
    }
}
